<template>
  <div class="person-info">
    <h2>姓名：{{ name }}</h2>
    <h2>年龄：{{ age }}</h2>
    <button @click="changeName">修改名字</button>
    <button @click="changeAge">修改年龄</button>
  </div>
</template>

<script lang="ts" setup name="personInfo">
import { reactive, toRefs, toRef } from "vue";
let person = reactive({
  name: "张三",
  age: 18,
});
//toRefs(person);把person的每一个属性结构为响应式对象
let { name, age } = toRefs(person);
//toRef(person, "age");把person的某一个属性结构为响应式对象
let n1 = toRef(person, "age");
console.log(person);
console.log(toRefs(person));
console.log(name);
console.log(age);
console.log(n1);

function changeName() {
  name.value += "~";
}
function changeAge() {
  age.value += 1;
}
</script>

<style scope>
.person-info {
  background-color: pink;
  box-shadow: 0 0 10px;
  border-radius: 10px;
  padding: 20px;
}
</style>